package com.lightjet.macross.base.feign.api.service.upms.Impl;

import com.lightjet.macross.base.feign.api.domain.AuthUser;
import com.lightjet.macross.base.feign.api.dto.upms.DeptViewClientDTO;
import com.lightjet.macross.base.feign.api.dto.upms.UserViewClientDTO;
import com.lightjet.macross.base.feign.api.remoteclient.BaseUPMSRemoteClient;
import com.lightjet.macross.base.feign.api.service.upms.UPMSDataMappingService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UPMSDataMappingServiceImpl implements UPMSDataMappingService {

    @Resource
    BaseUPMSRemoteClient baseUPMSRemoteClient;

    @Override
    @Cacheable(value = "dept", key = "'id:'+#id", unless = "#result eq null")
    public DeptViewClientDTO FindDeptById(String id) {
        return baseUPMSRemoteClient.GetDept(id.toString(),"").getData();
    }

    @Override
    @Cacheable(value = "user", key = "'id:'+#id", unless = "#result eq null")
    public UserViewClientDTO FindUserById(String id) {
        return baseUPMSRemoteClient.GetUser(id,"").getData();
    }

    @Override
    @Cacheable(value = "user", key = "'displayname:'+#id", unless = "#result eq null")
    public UserViewClientDTO FindUserByDisplayname(String displayname) {
        return baseUPMSRemoteClient.GetUserByDisplayname(displayname).getData();
    }

    @Override
    @Cacheable(value = "user", key = "'id_bean:'+#id+'@'+ #beanname", unless = "#result eq null")
    public AuthUser FindUserByIdAndUSIB(String id, String beanname) {
        return baseUPMSRemoteClient.GetUserBySystem(id,beanname).getData();
    }
}
